package cn.kpt.biz.controller;

import cn.kpt.beans.dto.Dto;
import cn.kpt.beans.vo.ItripImageVO;
import cn.kpt.beans.vo.ItripLabelDicVO;
import cn.kpt.beans.vo.hotelroom.ItripHotelRoomVO;
import cn.kpt.beans.vo.hotelroom.SearchHotelRoomVO;
import cn.kpt.biz.service.HotelRoomService;
import cn.kpt.biz.service.LabelDicService;
import cn.kpt.utils.DtoUtil;
import cn.kpt.utils.EmptyUtils;
import cn.kpt.utils.ErrorCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version 1.0
 * @ClassName HotelRoomController
 * @Description TODO
 * @Author kangpengtao
 * @Date 2019/10/16 15:51
 */
@Api(value = "API")
@RestController
@RequestMapping("/api/hotelroom")
public class HotelRoomController {
    @Resource
    private LabelDicService labelDicService;
    @Resource
    private HotelRoomService hotelRoomService;


    /**
     * 酒店详情-查询房间图片
     * @param roomId
     * @return
     */
    @ApiOperation(value = "根据targetId查询酒店房型图片(type=1)", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "根据酒店房型ID查询酒店房型图片" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码：</p>" +
            "<p>100301 : 获取酒店房型图片失败 </p>" +
            "<p>100302 : 酒店房型id不能为空</p>")
    @RequestMapping(value = "/getimg/{roomId}",method = RequestMethod.GET)
    public Dto doGetImg(@PathVariable Long roomId){
        try {
            List<ItripImageVO> vos = hotelRoomService.getImg(roomId);
            return DtoUtil.returnDataSuccess(vos);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("查询房间图片失败！",ErrorCode.BIZ_UNKNOWN);
        }
    }

    /**
     * 酒店详情-床型列表
     * @return
     */
    @ApiOperation(value = "查询酒店房间床型列表", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "查询酒店床型列表" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码：</p>" +
            "<p>100305 : 获取酒店房间床型失败</p>")
    @RequestMapping(value = "/queryhotelroombed",method = RequestMethod.GET)
    public Dto doQueryHotelRoomBed(){
        try {
            List<ItripLabelDicVO> vos = labelDicService.queryHotelRoomBed();
            return DtoUtil.returnDataSuccess(vos);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("查询床型失败！", ErrorCode.BIZ_UNKNOWN);
        }
    }
    /**
     * 酒店详情-房间列表查询
     * @param vo
     * @return
     */
    @ApiOperation(value = "查询酒店房间列表", httpMethod = "POST",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "查询酒店房间列表" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码：</p>" +
            "<p>100303 : 酒店id不能为空,酒店入住及退房时间不能为空,入住时间不能大于退房时间</p>" +
            "<p>100304 : 系统异常</p>")
    @RequestMapping(value = "/queryhotelroombyhotel",method = RequestMethod.POST)
    public Dto queryhotelroombyhotel(@RequestBody SearchHotelRoomVO vo){
        try {
            if (EmptyUtils.isEmpty(vo.getHotelId())) {
                return DtoUtil.returnFail("酒店ID不能为空", "100303");
            }
            if (EmptyUtils.isEmpty(vo.getStartDate()) || EmptyUtils.isEmpty(vo.getEndDate())) {
                return DtoUtil.returnFail("必须填写酒店入住及退房时间", "100303");
            }
            List<List<ItripHotelRoomVO>> vos = hotelRoomService.queryHotelRoomByHotel(vo);
            return DtoUtil.returnDataSuccess(vos);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("查询酒店房间失败！", ErrorCode.BIZ_UNKNOWN);
        }
    }
}
